package com.kamistoat.reactortest.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class OrderRouterFunction {

    @Autowired
    OrderHandlerFunction orderHandlerFunction;
    @Autowired
    OrderHandlerFunction_2 orderHandlerFunction_2;

    @Bean
    public RouterFunction<ServerResponse> orderRouter() {
        return RouterFunctions
                .route(RequestPredicates.GET("/order/delete/{id}").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), orderHandlerFunction)
                .andRoute(RequestPredicates.GET("/order/get/{id}").and(RequestPredicates.accept(MediaType.APPLICATION_JSON)), orderHandlerFunction_2::getOrderById);
    }
}
